package demo2;

class Animal{

}
class Alg<T extends Comparable<T>>{
    public T findMaxVal(T[] array){
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}

class Alg2{
    public static<T extends Comparable<T>> T findMaxVal(T[] array){
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}

class Alg3{
    public <T extends Comparable<T>> T findMaxVal(T[] array){
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}

public class Test {

    public static void main(String[] args) {
        Integer[] array = {1,2,31,41,5,61,73,99,8};
        Alg3 alg3 = new Alg3();
        // int ret = alg3.<Integer>findMaxVal(array);
        int ret = alg3.findMaxVal(array);
        System.out.println(ret);
    }

    public static void main2(String[] args) {
        Integer[] array = {1,2,31,41,5,61,73,99,8};
        // int ret = Alg2.<Integer>findMaxVal(array);
        int ret = Alg2.findMaxVal(array);
        System.out.println(ret);

    }

    public static void main1(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1,2,31,41,5,61,73,99,8};
        int ret = alg.findMaxVal(array);
        System.out.println(ret);
        // Alg<Animal> animalAlg = new Alg<Animal>();
    }
}
